/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.cv4j.app.slice;

import ohos.aafwk.content.Intent;
import ohos.agp.components.Image;
import ohos.media.image.PixelMap;

import com.cv4j.app.ResourceTable;
import com.cv4j.app.app.BaseAbilitySlice;
import com.cv4j.app.utill.PixelMapUtil;

import com.cv4j.core.filters.GaussianBlurFilter;
import com.cv4j.rxcv4j.RxImageData;
import com.cv4j.app.view.ProgressDialog;

/**
 * 高斯模糊
 *
 * @since 2021-05-18
 */
public class GaussianBlurAbilitySlice extends BaseAbilitySlice {
    private Image image1;
    private Image image2;
    private PixelMap pixelMap;
    private ProgressDialog dialog;

    /**
     * getUIContentLayoutId
     *
     * @return int
     */
    @Override
    protected int getUIContentLayoutId() {
        return ResourceTable.Layout_ability_gaussian_blur;
    }

    @Override
    protected void initComponents(Intent intent) {
        initView();
    }

    private void initView() {
        image1 = (Image) findComponentById(ResourceTable.Id_image1);
        image2 = (Image) findComponentById(ResourceTable.Id_image2);
        pixelMap = PixelMapUtil.getPixelMapFromResource(
            getContext(), ResourceTable.Media_test_filters).get();
        dialog = new ProgressDialog(getContext());
        useCV4j(image1);
        useCV4j(image2);
    }

    private void useCV4j(Image image) {
        // 需要补充加载圈dialog;
        GaussianBlurFilter filter = new GaussianBlurFilter();
        filter.setSigma(10.0);
        RxImageData.bitmap(pixelMap)
            .dialog(dialog)
            .addFilter(filter)
            .into(image);
    }
}
